import pyglet
import random
import time


from pyglet.window import Window
win = Window(width=640, height=480)
win.set_fullscreen(True)
win.set_mouse_visible(False)

a=True

@win.event
def on_key_press(symbol, modifiers):
    win.set_fullscreen(False)

@win.event
def on_draw():
    global a
    if a==False:
        pyglet.gl.glClearColor(random.random(),random.random(),random.random(),random.random())
        a=True
    else:
        pyglet.gl.glClearColor(0,0,0,0)
        a=False
    win.clear()


def update(dt):
    time.sleep(0.05)
pyglet.clock.schedule(update)



from pyglet import app
app.run()